<script>
	import interfaces from './utils/interfaces.js'
	import config from './utils/config.js'
	import tools from 'utils/tools.js'
	import {
		mapState
	} from 'vuex';
	export default {
		globalData: {
			start_id: 0,
		},
		methods: {},
		computed: {
			...mapState({
				userInfo: state => state.user.userInfo,
				platform: state => state.layout.platform
			}),
			checkUserInfo() {
				return {
					userInfo: this.userInfo,
					platform:this.platform,
					time: Date.now()
				}
			}
		},
		watch: {
			checkUserInfo: {
				handler(newVal) {
					// #ifdef MP-WEIXIN || MP-KUAISHOU
					if (typeof newVal.userInfo == 'object' && newVal.userInfo) {
						if (JSON.stringify(newVal.userInfo) != '{}') {
							if (!newVal.userInfo.ios_payment&&newVal.platform == 'ios') {
								console.warn('==============检查用户倒计时=========');
								let that = this;
								that.$store.commit('mut_startCountDown',that);
							}
						}
					}
					// #endif
				},
				deep: true
			},
		},
		created() {
			//都是到Storage获取
			//初始化获取用户openid
			this.$store.dispatch('act_openid');
			//初始化获取用户信息
			this.$store.dispatch('act_userInfo');
			//初始化获取spread_id
			this.$store.dispatch('act_spread_id');
		},
		onLaunch: function(options) {
			this.autoUpdate();
			this.checkStorage();
			let that = this;
			this.$store.commit('mut_initLayout'); //getSystemInfoSync()获取手机信息
			console.log('App Launch');
			// console.log(Date.now());
			if (typeof options == 'object' && options != null) {
				if (typeof options.referrerInfo == 'object' && options.referrerInfo != null) {
					if (JSON.stringify(options.referrerInfo) != '{}') {
						options.query = JSON.stringify(options.query);
						options.referrerInfo = JSON.stringify(options.referrerInfo);
						console.log(63,options);
						this.request({ //用户信息
							url: interfaces.indexs,
							method: "POST",
							data: options,
							success: (ires) => {}
						})
					}
				}
			}
		},
		onShow: function(options) {
			console.log('App Show')
			
			// console.log(Date.now());
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods: {
			autoUpdate: function() { //检查版本更新
				let diyversion = uni.getStorageSync('diyversion') ?  uni.getStorageSync('diyversion') : ''
				if(!diyversion || config.version>diyversion ){
					console.log(87)
					// uni.clearStorageSync();
					uni.setStorageSync("clickC" , 0)
					uni.setStorageSync("releaseTime" , 0)
					uni.setStorageSync('diyversion',config.version)
				}
				console.warn('======检查版本更新=====');
				// const updateManager = uni.getUpdateManager();
				// updateManager.onCheckForUpdate(function(res) {
				// 	console.warn('检查结果',res);
				// 	if (res.hasUpdate) {
				// 		updateManager.onUpdateReady(function() {
				// 			uni.showModal({
				// 				title: '更新提示',
				// 				content: '新版本已经准备好，是否重启应用？',
				// 				showCancel: false,
				// 				confirmColor: '#ED7B3C',
				// 				confirmText: '马上重启',
				// 				success(res) {
				// 					if (res.confirm) {
				// 						updateManager.applyUpdate();
				// 						uni.clearStorageSync();
				// 					}
				// 				}
				// 			})
				// 		})
				// 	}
				// })
			},
			
			checkStorage(){
				try{
					const res = uni.getStorageInfoSync()
					console.log(121,res.keys)
					console.log(122,res.currentSize)
					console.log(123,res.limitSize)
				}catch(e){
					//TODO handle the exception
				}
			}
		}
	}
</script>
<style lang="scss">
	.pageblack {
		background-color: #282934 !important;
	}

	.videoBottomBg {
		background-color: #000000 !important;
	}

	@import "@/uni_modules/uview-ui/index.scss";
	/*每个页面公共css */
	@import './common/css/common.css';
	@import './common/css/iconfont.css';
</style>